package com.syzg.base.aduit.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.syzg.base.aduit.model.Audit;
import com.syzg.base.aduit.service.AuditService;
import com.syzg.common.config.SysProperties;
import com.syzg.common.model.WebObj;
import com.syzg.common.util.SearchMap;
import com.syzg.core.page.PageResult;
import com.syzg.core.util.StringUtil;
import com.zenithsun.common.security.csrf.CSRFTokenManager;

@Controller
@RequestMapping("/sys/audit")
public class AuditController {
	@Resource
	private AuditService auditService;

	@SuppressWarnings("static-access")
	@RequestMapping("/list")
	public ModelAndView listAudit(WebObj webObj,Audit audit,HttpServletRequest request) throws Exception {
		/**** XSS ****/
		//CSRFTokenManager.validateForm(request);
		ModelAndView mv = new ModelAndView("/zenithsun/common/audit/audit.jsp");
		SearchMap searchMap = SearchMap.forClass(Audit.class);
		
		/*if(audit.getPerson() != null )
		{
			if(StringUtil.isNotBlank(audit.getPerson().getAccount())){
				searchMap.eq("a.person.account", audit.getPerson().getAccount());
			}
		}*/
		if(StringUtil.isNotBlank(audit.getType())){
			searchMap.eq("a.type", audit.getType());
		}
		if(StringUtil.isNotBlank(audit.getFlag())){
			searchMap.eq("a.flag", audit.getFlag());
		}
		searchMap.addOrder("date", searchMap.ORDER_DESC);
		PageResult pageResult = auditService.findObjectsForPage(webObj.getPageNo(), SysProperties.PAGESIZE, searchMap);
		webObj.setPageResult(pageResult);
		mv.addObject("webObj", webObj);
		mv.addObject("audit", audit);
		return mv;
	}
}
